<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryRef" inline>
          <el-form-item label="试卷名称" prop="paperName">
            <el-input
              v-model="queryParams.paperName"
              placeholder="请输入试卷名称"
              clearable
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table
          v-loading="loading"
          :data="paperList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            label="学科"
            align="center"
            key="subject"
            prop="subject"
            show-overflow-tooltip
          />
          <el-table-column
            label="试卷名称"
            align="center"
            key="examName"
            prop="examName"
            show-overflow-tooltip
          />
          <el-table-column
            label="提交人"
            align="center"
            key="stuName"
            prop="stuName"
            show-overflow-tooltip
          />

          <!-- <el-table-column label="参考班级" align="center">
            <template #default="scope">
              <span>{{
                scope.row.classInfoList.map((item) => item.className).toString()
              }}</span>
            </template>
          </el-table-column> -->
          <!-- <el-table-column label="考试时长" align="center">
            <template #default="scope">
              <span>{{ scope.row.duration }}分钟</span>
            </template>
          </el-table-column> -->
          <el-table-column
            label="提交时间"
            align="center"
            prop="pulltime"
            width="160"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.pulltime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template #default="scope">
              <el-button
                type="primary"
                link
                icon="Edit"
                @click="handleStartTest(scope.row)"
                >开始批改
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
  </div>
</template>

<script setup name="Class">
import { getStuAnswerFinish } from "@/api/core/test";
import { getSubjectList } from "@/api/core/subject";
import { getTopicList } from "@/api/core/topic";
import { getSchoolClassList } from "@/api/core/class";
import {
  getCurrentInstance,
  reactive,
  ref,
  toRefs,
  watch,
  computed,
} from "vue";
import { parseTime } from "@/utils/ruoyi";
import useUserStore from "@/store/modules/user";

const { proxy } = getCurrentInstance();
const router = useRouter();
const paperList = ref([]);
const loading = ref(true);
const total = ref(0);
const userStore = useUserStore();

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    paperName: undefined,
  },
});
const { queryParams } = toRefs(data);

/** 查询试卷列表 */
function getList() {
  loading.value = true;
  getStuAnswerFinish(queryParams.value).then((res) => {
    loading.value = false;
    paperList.value = res.rows;
    total.value = res.total;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 开始考试
function handleStartTest(row) {
  proxy.$modal
    .confirm("是否开始批改？")
    .then(() => {
      router.push({
        path: "/test/checkDetail",
        query: {
          paperId: row.examPaperId,
          studentId: row.studentId,
          id: row.id,
        },
      });
    })
    .catch(() => {});
}

getList();
</script>

<style scoped lang="scss"></style>
